Skip to content

Add multiple assignment support to type inference#50

Merged
dak2 merged 1 commit into
mainfrom
add-multi-assign-support
Mar 8, 2026
Merged

Add multiple assignment support to type inference#50
dak2 merged 1 commit into
mainfrom
add-multi-assign-support

Conversation

@dak2

@dak2 dak2 commented Mar 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add support for Ruby multiple assignment (a, b = 1, "hello") in the type inference engine
  • When RHS is an ArrayNode (multiple literal values), each element is paired with its corresponding LHS target via zip, enabling correct per-variable type inference
  • Non-ArrayNode RHS (single expression, method return decomposition) registers variables as untyped to prevent panics
  • New assignments.rs module follows the existing process_*_node pattern

Test plan

  • test_multi_write_integer_and_stringa, b = 1, "hello" → a: Integer, b: String
  • test_multi_write_all_integera, b, c = 1, 2, 3 → all Integer
  • test_multi_write_variable_reference_after_assignmenta, b = 1, "hello"; x = a → x: Integer
  • test_multi_write_lhs_longer_than_rhsa, b, c = 1, 2 → zip skips c (known v0.1.8 limitation)
  • test_multi_write_does_not_panic_on_non_array_rhsa, b = some_expr → no panic, variables registered as untyped

🤖 Generated with Claude Code

Ruby's multiple assignment (e.g., `a, b = 1, "hello"`) is a common
pattern that previously caused the type checker to skip variable
registration entirely. This meant any subsequent use of variables
assigned via multiple assignment would be untyped, leading to false
negatives in method chain validation.

This commit handles the ArrayNode RHS case where each literal value
on the right-hand side is paired with its corresponding target on the
left-hand side via zip. Non-ArrayNode RHS (single expression, method
return decomposition) falls back to registering variables as untyped
to prevent panics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dak2 dak2 merged commit 109aa29 into main Mar 8, 2026
2 checks passed
@dak2 dak2 deleted the add-multi-assign-support branch March 8, 2026 07:10
@dak2 dak2 mentioned this pull request Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant